package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;

@WebServlet("/servletDemo2")
public class ServletDemo2 extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      //根据名称获取数据
       String username = request.getParameter("username");
        System.out.println(username);
        String passworld = request.getParameter("passworld");
        System.out.println(passworld);
        System.out.println("-------");

//        根据名称获取所有数据
        String[] hobbys = request.getParameterValues("hobby");
        for (String hobby : hobbys) {
            System.out.println(hobby);
        }
        System.out.println("-------");

        //获取所有名称
        Enumeration<String> names = request.getParameterNames();
        while (names.hasMoreElements()){
            String s = names.nextElement();
            System.out.println(s);
        }
        System.out.println("-------");
        Map<String, String[]> map = request.getParameterMap();
        for (String key : map.keySet()) {
            System.out.print(key+",");
            String[] values = map.get(key);
            for (String value : values) {
                System.out.print(value);
                System.out.println();
            }

        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
